using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.Web;
using CMS.Presenters.Views.ListManager;
using CMS.Presenters.Presenters.ListManager;
using CMS.Core.Domain;
using CMS.Data;
using System.Collections.Generic;

namespace CMS.Web.ListManager
{
    public partial class ListCauHinh : BaseUserControl, IListCauHinhBCView
    {
        ListCauHinhBCPresenter presenter;
        IList<CauHinhBC> objIList;
        public bool isRole = false;
        NguoiSuDungInfo userInfo;

        public ListCauHinh()
        {
            this.presenter = new ListCauHinhBCPresenter(this, NHibernateDaoFactory.Instance.GetCauHinhBCDao());
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            presenter.CancelUpdateEvent += new EventHandler(HandleCancelUpdateEvent);
        }

        private void HandleCancelUpdateEvent(object sender, EventArgs e)
        {
            Response.Redirect(BaseUrl + "&action=VIEW");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            userInfo = (NguoiSuDungInfo)Session["UserInfo"];
            presenter.LoadViewFromModel(userInfo.ID);
            if (!this.IsPostBack)
            {
                this.gridObj.DataSource = this.objIList;
                this.gridObj.DataBind();
            }
        }

        #region Grid Members
        // For swich page
        protected void gridObj_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.gridObj.DataSource = this.objIList;
            gridObj.PageIndex = e.NewPageIndex;
            gridObj.DataBind();

        }
        #endregion

        #region ILoaiVBView Members

        public bool IsValid
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public IList<CauHinhBC> CauHinhBCList
        {
            get { return this.objIList; }
            set { this.objIList = value; }
            
        }
        #endregion        

        protected void gridObj_RowCreated(object sender, GridViewRowEventArgs e)
        {           
                        if (e.Row.RowType == DataControlRowType.Pager)
            {
                foreach (Control c in e.Row.Cells[0].Controls)
                {
                    if (c.GetType().ToString().Equals("System.Web.UI.WebControls.PagerTable"))
                    {
                        Table tbl = (Table)c;
                        TableCell cell = new TableCell();
                        cell.Text = "Trang ";
                        cell.HorizontalAlign = HorizontalAlign.Right;
                        tbl.Rows[0].Cells.AddAt(0, cell);
                    }
                }
            }
        }

        #region ILoaiVBView Members


        public bool IsRole
        {
            get
            {
                return this.isRole;
            }
            set
            {
                this.isRole = value;
            }
        }

        #endregion
    }
}